local ClientOHOH = _G.ClientOHOH;
local M = ClientOHOH.class.new(script, ClientOHOH.files.Client_PlayerComponent(),script.Parent.Name);
local EventList = ClientOHOH.load.EventList();
gOnboardingFunnel=require(script.Parent.OnboardingFunnel)


function M.new(self,...)
	return M(self,...);
end;

function M.ctor(self, parent)
	M.super.ctor(self, parent);

    self.HadOnboardingFunnel={}

    self.OnboardingFunnelEvent=self.parent.OnboardingFunnelEvent
    self.OnboardingFunnelEvent:Connect(function(id,customFields)
        -- self:AddOnboardingFunnel(id,customFields)

        -- self:AddProcess(function()
        --     self:Fire(EventList.game_analytics_onboardingFunnelEvent,id,customFields)
        --     self.HadOnboardingFunnel[id]=true
        -- end)

        self:Fire(EventList.game_analytics_onboardingFunnelEvent,id,customFields)
    end)

end;


function M.multi_step_name(self,setpName,customFields)
    local countKey=setpName.."_count"
    if not self[countKey] then
        self[countKey]=1
    else
       local nextId=  self[countKey]+1
       local id=string.format("%s_%s",setpName,nextId)
       local cfg= gOnboardingFunnel[id]
       if cfg.preDone then
            if  self.HadOnboardingFunnel[cfg.preDone] then
                self[countKey]=nextId
            end
       else
            self[countKey]=nextId
       end
    end

    local id=string.format("%s_%s", setpName,self[countKey])


    if not gOnboardingFunnel[id] then
        return 
    end
    self:AddOnboardingFunnel(id,customFields)

end


function M.AddOnboardingFunnel(self,id,customFields)

    if gOnboardingFunnel.multi_step_name[id] then
        self:multi_step_name(id,customFields)
        return 
    end

    if not gOnboardingFunnel[id] then

        return 
    end

    if  self.HadOnboardingFunnel[id] then --只打点一次，已经打过的不用发送
        return
    end

    self:Fire(EventList.game_analytics_onboardingFunnelEvent,id,customFields)
    self.HadOnboardingFunnel[id]=true
end

function M.dtor(self)
	M.super.dtor(self);
end;

return M